package com.itheima.work03;

import java.util.Comparator;
import java.util.Iterator;
import java.util.TreeSet;

public class TestStudent {
    public static void main(String[] args) {
        TreeSet<Student> stu = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int i = o1.getName().compareTo(o2.getName());
                return i;
            }
        });

        Student s1 = new Student("张三", "男", "20");
        Student s2 = new Student("李四", "女", "21");
        Student s3 = new Student("张三", "男", "20");

        stu.add(s1);
        stu.add(s2);
        stu.add(s3);

        Iterator<Student> iterator = stu.iterator();
        while (iterator.hasNext()){
            Student next = iterator.next();
            System.out.println(next);
        }
    }
}
